﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

public class NetWorkMgr : Singleton<NetWorkMgr>
{

    public void Start()
    {
        //创建tcpserver实例
        m_tcpServer = TCPServer.CreateServer("WinterServer");
        //开启打印接收到数据的Hex
        m_tcpServer.PrintReceiveHex = true; 
        //开启打印发送数据的Hex
        m_tcpServer.PrintSendHex = true; 
        //协议头字节数
        m_tcpServer.HeaderLength = 8;
        //开始监听
        m_tcpServer.Start(8001);
    }

    public void SendMsg(string id,byte[] bytes)
    {
        m_tcpServer.Send(id, bytes, false);
    }

    //停止服务器
    public void Stop()
    {
        m_tcpServer.Stop();
    }

    //重启服务器
    public void ReStart()
    {
        m_tcpServer.Stop();
        Start();
    }

    private TCPAsyncServer m_tcpServer = null;

}


    

